import * as SignalR from "@aspnet/signalr";
import {host} from '../config/config'
import { Message } from 'element-ui';
//连接集线器
export var connectionSignalR = new SignalR.HubConnectionBuilder()
    .withUrl(host+"chatHub?isPower="+sessionStorage.getItem("isPower"), {
        accessTokenFactory: () => sessionStorage.getItem("token"),
        transport: SignalR.HttpTransportType.WebSockets,
    })
    .configureLogging(SignalR.LogLevel.None) //日志输出级别,可自行调整
    .build();
// //监听到关闭后,每过5秒请求重新连接一次
connectionSignalR.onclose(() => {
    Message.error("聊天与服务器断开连接请尝试刷新")
    // var currTimeOut = null;
    // currTimeOut = window.setInterval(() => {
    //     Message({
    //         message: '正在重新连接服务器',
    //         type: 'warning'
    //       });
    //     connectionSignalR.start().then(() => {
    //         Message({
    //             message: '连接服务器成功',
    //             type: 'success'
    //           });
    //         window.clearInterval(currTimeOut);
    //         currTimeOut = null;
    //     })
    // }, 5000)
})
